package com.hzhr.iot.core.constant;

import org.springframework.http.HttpStatus;
import org.springframework.util.StringUtils;

public enum  Common_ErrorsEnum implements ServiceErrors {
    COMMON_0(0, "未知异常", ServiceExceptionCategory.COMMON_EXCEPTION),
    COMMON_1(1, "无法获取日志模型", ServiceExceptionCategory.COMMON_EXCEPTION),
    COMMON_2(2, "无权限", ServiceExceptionCategory.COMMON_EXCEPTION, HttpExceptionCategory.CLIENT_EXCEPTION, HttpStatus.UNAUTHORIZED),

    COMMON_3(3, "header验证错误", ServiceExceptionCategory.COMMON_EXCEPTION, HttpExceptionCategory.CLIENT_EXCEPTION, HttpStatus.BAD_REQUEST),
    COMMON_4(4, "body验证错误", ServiceExceptionCategory.COMMON_EXCEPTION, HttpExceptionCategory.CLIENT_EXCEPTION, HttpStatus.BAD_REQUEST),
    COMMON_5(5, "pathVariable验证错误", ServiceExceptionCategory.COMMON_EXCEPTION, HttpExceptionCategory.CLIENT_EXCEPTION, HttpStatus.BAD_REQUEST),

    COMMON_6(6, ServiceExceptionCategory.ARG_EXCEPTION, HttpExceptionCategory.CLIENT_EXCEPTION, HttpStatus.BAD_REQUEST);

    private Integer code;
    private String message;
    private ServiceExceptionCategory serviceExceptionCategory;
    private HttpExceptionCategory httpExceptionCategory;
    private HttpStatus httpStatus;
    Common_ErrorsEnum(Integer code, ServiceExceptionCategory serviceExceptionCategory, HttpExceptionCategory httpExceptionCategory, HttpStatus httpStatus) {
        this.code = code;
        this.serviceExceptionCategory = serviceExceptionCategory;
        this.httpExceptionCategory = HttpExceptionCategory.SERVICE_EXCEPTION;
        this.httpStatus = HttpStatus.INTERNAL_SERVER_ERROR;
    }
    Common_ErrorsEnum(Integer code, String message, ServiceExceptionCategory serviceExceptionCategory) {
        this.code = code;
        this.message = message;
        this.serviceExceptionCategory = serviceExceptionCategory;
        this.httpExceptionCategory = HttpExceptionCategory.SERVICE_EXCEPTION;
        this.httpStatus = HttpStatus.INTERNAL_SERVER_ERROR;
    }
    Common_ErrorsEnum(Integer code, String message, ServiceExceptionCategory serviceExceptionCategory, HttpExceptionCategory httpExceptionCategory, HttpStatus httpStatus) {
        this.code = code;
        this.message = message;
        this.serviceExceptionCategory = serviceExceptionCategory;
        this.httpExceptionCategory = httpExceptionCategory;
        this.httpStatus = httpStatus;
    }
    @Override
    public Integer getCode() {
        return code;
    }
    @Override
    public String getBusiness() {
        return null;
    }
    @Override
    public String getMessage() {
        return message;
    }
    @Override
    public ServiceExceptionCategory getServiceExceptionCategory() {
        return serviceExceptionCategory;
    }
    @Override
    public HttpExceptionCategory getHttpExceptionCategory() {
        return httpExceptionCategory;
    }
    @Override
    public HttpStatus getHttpStatus() {
        return httpStatus;
    }
    @Override
    public void setMessage(String message) {
        this.message = message;
    }

    public static Common_ErrorsEnum getEnumByName(String name) {
        if (StringUtils.isEmpty(name)) return null;
        for (Common_ErrorsEnum user_errorsEnum : Common_ErrorsEnum.values()) {
            if (user_errorsEnum.name().equals(name)) {
                return user_errorsEnum;
            }
        }
        return null;
    }
}
